/*
* This file is a part of the open-eBackup project.
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
* If a copy of the MPL was not distributed with this file, You can obtain one at
* http://mozilla.org/MPL/2.0/.
*
* Copyright (c) [2024] Huawei Technologies Co.,Ltd.
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
*/
#include "stub.h"
#include "gtest/gtest.h"
#include "gmock/gmock.h"
#include "gmock/gmock-actions.h"
#include "HetroBackupJob.h"
#include "ScanMgr.h"
#include "Backup.h"
#include "JsonHelper.h"
#include "PluginUtilities.h"
#include "device_access/dorado/DoradoBlock.h"


using ::testing::_;
using testing::AllOf;
using ::testing::AnyNumber;
using ::testing::AtLeast;
using testing::ByMove;
using testing::DoAll;
using ::testing::Eq;
using ::testing::Field;
using ::testing::Ge;
using ::testing::Gt;
using testing::InitGoogleMock;
using ::testing::Invoke;
using ::testing::Ne;
using ::testing::Return;
using ::testing::Sequence;
using ::testing::SetArgReferee;
using ::testing::SetArgumentPointee;
using ::testing::Throw;
using namespace std;
using namespace FS_Backup;
using namespace Module;

namespace {
constexpr int NAS_SCANNER_THREAD_CNT = 32;
constexpr int NAS_BACKUP_THREAD_CNT = 32;
}

namespace Backup_Test {
class BackupTest : public Backup {
public:
    explicit BackupTest(const BackupParams &backupParams);
    BackupTest(std::string source, std::string destination);
    ~BackupTest() override;

    BackupRetCode Start() override;
    BackupRetCode Abort() override;
    BackupRetCode Destroy() override;
    BackupRetCode Enqueue(std::string contrlFile) override;
    BackupPhaseStatus GetStatus() override;
    BackupStats GetStats() override;
    std::unordered_set<FailedRecordItem, FailedRecordItemHash> GetFailedDetails() override;
};


BackupTest::BackupTest(const BackupParams &backupParams) : Backup(backupParams) {};

BackupTest::~BackupTest() {};

BackupRetCode BackupTest::Start()
{
    return BackupRetCode::SUCCESS;
}
BackupRetCode BackupTest::Abort()
{
    return BackupRetCode::SUCCESS;
}
BackupRetCode BackupTest::Destroy()
{
    return BackupRetCode::SUCCESS;
}
BackupRetCode BackupTest::Enqueue(std::string contrlFile)
{
    return BackupRetCode::SUCCESS;
}
BackupPhaseStatus BackupTest::GetStatus()
{
    return BackupPhaseStatus::COMPLETED;
}
BackupStats BackupTest::GetStats()
{
    BackupStats backupStats;
    return backupStats;
}
std::unordered_set<FailedRecordItem, FailedRecordItemHash> BackupTest::GetFailedDetails() {
    std::unordered_set<FailedRecordItem, FailedRecordItemHash> ret;
    return ret;
}

class BackupTestFailed : public Backup {
public:
    explicit BackupTestFailed(const BackupParams &backupParams);
    BackupTestFailed(std::string source, std::string destination);
    ~BackupTestFailed() override;

    BackupRetCode Start() override;
    BackupRetCode Abort() override;
    BackupRetCode Destroy() override;
    BackupRetCode Enqueue(std::string contrlFile) override;
    BackupPhaseStatus GetStatus() override;
    BackupStats GetStats() override;
    std::unordered_set<FailedRecordItem, FailedRecordItemHash> GetFailedDetails() override;
};


BackupTestFailed::BackupTestFailed(const BackupParams &backupParams) : Backup(backupParams) {};

BackupTestFailed::~BackupTestFailed() {};

BackupRetCode BackupTestFailed::Start()
{
    return BackupRetCode::SUCCESS;
}
BackupRetCode BackupTestFailed::Abort()
{
    return BackupRetCode::SUCCESS;
}
BackupRetCode BackupTestFailed::Destroy()
{
    return BackupRetCode::SUCCESS;
}
BackupRetCode BackupTestFailed::Enqueue(std::string contrlFile)
{
    return BackupRetCode::SUCCESS;
}
BackupPhaseStatus BackupTestFailed::GetStatus()
{
    return BackupPhaseStatus::FAILED;
}
BackupStats BackupTestFailed::GetStats()
{
    BackupStats backupStats;
    return backupStats;
}
std::unordered_set<FailedRecordItem, FailedRecordItemHash> BackupTestFailed::GetFailedDetails() {
    std::unordered_set<FailedRecordItem, FailedRecordItemHash> ret;
    return ret;
}

class BackupTestAborted : public Backup {
public:
    explicit BackupTestAborted(const BackupParams &backupParams);
    BackupTestAborted(std::string source, std::string destination);
    ~BackupTestAborted() override;

    BackupRetCode Start() override;
    BackupRetCode Abort() override;
    BackupRetCode Destroy() override;
    BackupRetCode Enqueue(std::string contrlFile) override;
    BackupPhaseStatus GetStatus() override;
    BackupStats GetStats() override;
    std::unordered_set<FailedRecordItem, FailedRecordItemHash> GetFailedDetails() override;
};


BackupTestAborted::BackupTestAborted(const BackupParams &backupParams) : Backup(backupParams) {};

BackupTestAborted::~BackupTestAborted() {};

BackupRetCode BackupTestAborted::Start()
{
    return BackupRetCode::SUCCESS;
}
BackupRetCode BackupTestAborted::Abort()
{
    return BackupRetCode::SUCCESS;
}
BackupRetCode BackupTestAborted::Destroy()
{
    return BackupRetCode::SUCCESS;
}
BackupRetCode BackupTestAborted::Enqueue(std::string contrlFile)
{
    return BackupRetCode::SUCCESS;
}
BackupPhaseStatus BackupTestAborted::GetStatus()
{
    return BackupPhaseStatus::ABORTED;
}
BackupStats BackupTestAborted::GetStats()
{
    BackupStats backupStats;
    return backupStats;
}
std::unordered_set<FailedRecordItem, FailedRecordItemHash> BackupTestAborted::GetFailedDetails() {
    std::unordered_set<FailedRecordItem, FailedRecordItemHash> ret;
    return ret;
}

class BackupTestAbortInprogress : public Backup {
public:
    explicit BackupTestAbortInprogress(const BackupParams &backupParams);
    BackupTestAbortInprogress(std::string source, std::string destination);
    ~BackupTestAbortInprogress() override;

    BackupRetCode Start() override;
    BackupRetCode Abort() override;
    BackupRetCode Destroy() override;
    BackupRetCode Enqueue(std::string contrlFile) override;
    BackupPhaseStatus GetStatus() override;
    BackupStats GetStats() override;
    std::unordered_set<FailedRecordItem, FailedRecordItemHash> GetFailedDetails() override;
};


BackupTestAbortInprogress::BackupTestAbortInprogress(const BackupParams &backupParams) : Backup(backupParams) {};

BackupTestAbortInprogress::~BackupTestAbortInprogress() {};

BackupRetCode BackupTestAbortInprogress::Start()
{
    return BackupRetCode::SUCCESS;
}
BackupRetCode BackupTestAbortInprogress::Abort()
{
    return BackupRetCode::SUCCESS;
}
BackupRetCode BackupTestAbortInprogress::Destroy()
{
    return BackupRetCode::SUCCESS;
}
BackupRetCode BackupTestAbortInprogress::Enqueue(std::string contrlFile)
{
    return BackupRetCode::SUCCESS;
}
BackupPhaseStatus BackupTestAbortInprogress::GetStatus()
{
    return BackupPhaseStatus::ABORT_INPROGRESS;
}
BackupStats BackupTestAbortInprogress::GetStats()
{
    BackupStats backupStats;
    return backupStats;
}
std::unordered_set<FailedRecordItem, FailedRecordItemHash> BackupTestAbortInprogress::GetFailedDetails() {
    std::unordered_set<FailedRecordItem, FailedRecordItemHash> ret;
    return ret;
}
} // namespace Backup_Test

static int ExecuteCopyMetaSubJobInner_Stub(HetroBackupSubJob backupSubJob)
{
    return Module::SUCCESS;
}

static unique_ptr<FS_Backup::Backup> CreateBackupInstStub_Succ(void *obj, BackupParams backupParams)
{
    BackupParams emptyInfo;
    return std::make_unique<Backup_Test::BackupTest>(emptyInfo);
}

static unique_ptr<FS_Backup::Backup> CreateBackupInstStub_Failed(void *obj, BackupParams backupParams)
{
    BackupParams emptyInfo;
    return std::make_unique<Backup_Test::BackupTestFailed>(emptyInfo);
}

static unique_ptr<FS_Backup::Backup> CreateBackupInstStub_Aborted(void *obj, BackupParams backupParams)
{
    BackupParams emptyInfo;
    return std::make_unique<Backup_Test::BackupTestAborted>(emptyInfo);
}

static unique_ptr<FS_Backup::Backup> CreateBackupInstStub_AbortInprogress(void *obj, BackupParams backupParams)
{
    BackupParams emptyInfo;
    return std::make_unique<Backup_Test::BackupTestAbortInprogress>(emptyInfo);
}

static bool Initiate_Stub_Succ(void *obj, const ScanConfig &scanConfig)
{
    return true;
}

static SCANNER_STATUS StartScan_Stub_Succ(void* obj) {
    return SCANNER_STATUS::SUCCESS;
}

static SCANNER_STATUS AbortScan_Stub_Succ(void* obj) {
    return SCANNER_STATUS::SUCCESS;
}

static void Destroy_Stub(void* obj) {
    return;
}

static void Enqueue_Stub(void* obj, std::string directory, std::string prefix, uint8_t filterFlag) {
    return;
}

static SCANNER_STATUS GetScanStatus_Stub_Completed(void* obj) {
    return SCANNER_STATUS::COMPLETED;
}

static ScanStatistics GetScanStats_Stub(void* obj) {
    ScanStatistics scanStatistics;
    return scanStatistics;
}

class HetroBackupJobTest : public testing::Test {
public:
    void SetUp();
    void TearDown();
    void SetUpGenSubJobInfo();
    void TearDownGenSubJobInfo();
    void SetUpExecSubJobInfo();
    void TearDownExecSubJobInfo();
    static void SetUpTestCase();
    static void TearDownTestCase();
    // AppProtect::BackupJob BackupJobSetup();
    // HetroBackupJob m_hetroBackupJobObj;
    // std::unique_ptr<HetroBackupJob> m_hetroBackupJobObj;
    std::unique_ptr<HetroBackupJob> m_hetroBackupJobObj = std::make_unique<HetroBackupJob>();
    Stub stub;
};

static AppProtect::BackupJob BackupJobSetup()
{
    AppProtect::BackupJob backupJob;
    backupJob.requestId = "reqId123";
    backupJob.jobId = "jId123";
    backupJob.jobParam.backupType = AppProtect::BackupJobType::FULL_BACKUP;
    backupJob.jobParam.dataLayout.extendInfo = "xxx";
    string filterString;
    AppProtect::ResourceFilter fileFilter;
    fileFilter.filterBy = "Name";
    fileFilter.type = "File";
    fileFilter.mode = "INCLUDE";
    fileFilter.rule = "Fuzzy";
    filterString = "/a";
    fileFilter.values.push_back(filterString);
    AppProtect::ResourceFilter dirFilter;
    dirFilter.filterBy = "Name";
    dirFilter.type = "Dir";
    dirFilter.mode = "INCLUDE";
    dirFilter.rule = "Fuzzy";
    filterString = "/b";
    dirFilter.values.push_back(filterString);
    AppProtect::ResourceFilter formatFilter;
    formatFilter.filterBy = "Format";
    formatFilter.type = "File";
    formatFilter.mode = "INCLUDE";
    formatFilter.rule = "Exact";
    filterString = "1";
    formatFilter.values.push_back(filterString);
    filterString = "2";
    formatFilter.values.push_back(filterString);
    filterString = "3";
    formatFilter.values.push_back(filterString);
    filterString = "4";
    formatFilter.values.push_back(filterString);
    filterString = "5";
    formatFilter.values.push_back(filterString);
    filterString = "6";
    formatFilter.values.push_back(filterString);
    AppProtect::ResourceFilter dateFilter;
    dateFilter.filterBy = "ModifyTime";
    dateFilter.type = "File";
    dateFilter.mode = "INCLUDE";
    dateFilter.rule = "Exact";
    filterString = "1641839400533";
    dateFilter.values.push_back(filterString);
    filterString = "1641943800694";
    dateFilter.values.push_back(filterString);
    backupJob.jobParam.filters.push_back(fileFilter);
    backupJob.jobParam.filters.push_back(dirFilter);
    backupJob.jobParam.filters.push_back(formatFilter);
    backupJob.jobParam.filters.push_back(dateFilter);
    backupJob.jobParam.advanceParams = "{\"small_file_aggregation\":\"0\",\"aggregate_level\":\"0\","
        "\"permissions_and_attributes\":\"1\"}";
    backupJob.protectEnv.id = "peId123";
    backupJob.protectEnv.name = "poName123";
    backupJob.protectEnv.type = "Vendor";
    backupJob.protectEnv.subType = "StorageOthers";
    backupJob.protectEnv.endpoint = "10.28.12.144";
    backupJob.protectEnv.port = 8080;
    backupJob.protectEnv.auth.extendInfo = "{\"fingerPrint\" : \"4928EBB6E58A3A395BC89317DD55B82F1B8C10E7\"}";
    backupJob.protectEnv.extendInfo = "{\"snapConsistency\":\"0\",\"verifyStatus\":\"1\",\"wwn\":\"\"}";
    backupJob.protectObject.id = "poID123";
    backupJob.protectObject.type = "storage";
    backupJob.protectObject.subType = "NasShare";
    backupJob.protectObject.name = "OceanstorFS";
    backupJob.protectObject.auth.authType = AuthType::NO_AUTHENTICATION;
    backupJob.protectObject.auth.authkey = "";
    backupJob.protectObject.auth.authPwd = "";
    backupJob.protectObject.extendInfo = "{\"authMode\":\"1\",\"filters\":\"\",\"ip\":\"10.28.12.144\""
        ",\"kerberosId\":\"0\",\"shareMode\":\"1\"}";
    string path = "/MetaFS/cache";
    HostAddress hostadd;
    hostadd.ip = "10.28.12.144";
    StorageRepository cacheRepo;
    cacheRepo.repositoryType = RepositoryDataType::CACHE_REPOSITORY;
    cacheRepo.path.push_back(path);
    cacheRepo.remotePath = "/MetaFS/cache";
    cacheRepo.remoteHost.push_back(hostadd);
    cacheRepo.auth.authkey = "admin";
    cacheRepo.auth.authPwd = "Admin@123";
    cacheRepo.endpoint.ip = "10.28.12.144";
    cacheRepo.endpoint.port = 8088;
    StorageRepository dataRepo;
    dataRepo.repositoryType = RepositoryDataType::DATA_REPOSITORY;
    dataRepo.remotePath = "/BackupFS";
    dataRepo.path.push_back(dataRepo.remotePath);
    dataRepo.remoteHost.push_back(hostadd);
    dataRepo.auth.authkey = "admin";
    dataRepo.auth.authPwd = "Admin@123";
    dataRepo.endpoint.ip = "10.28.12.144";
    dataRepo.endpoint.port = 8088;
    StorageRepository metaRepo;
    metaRepo.repositoryType = RepositoryDataType::META_REPOSITORY;
    path = "/MetaFS/meta";
    metaRepo.path.push_back(path);
    metaRepo.remotePath = "/MetaFS/meta";
    metaRepo.remoteHost.push_back(hostadd);
    metaRepo.auth.authkey = "admin";
    metaRepo.auth.authPwd = "Admin@123";
    metaRepo.endpoint.ip = "10.28.12.144";
    metaRepo.endpoint.port = 8088;
    backupJob.repositories.push_back(cacheRepo);
    backupJob.repositories.push_back(dataRepo);
    backupJob.repositories.push_back(metaRepo);
    backupJob.extendInfo = "{\"auto_index\":\"false\",\"permissions_and_attributes\":\"0\",\"proxy_host_mode\":\"0\","
        "\"small_file_aggregation\":\"0\"}";
    return backupJob;
}

static bool ReportJobDetails_Stub_SUC(void *ob, SubJobDetails &jobInfo)
{
    return true;
}

static bool ReportJobDetails_Stub_FAIL(void *ob, SubJobDetails &jobInfo)
{
    return false;
}

static bool ReadBackupCopyFromFile_Stub_SUC(void *ob, std::string backupCopyPathFullPath,
    HetroLastCopyDetails &backupCopy)
{
    return true;
}

static bool ReadBackupCopyFromFile_Stub_Fail(void *ob, std::string backupCopyPathFullPath,
    HetroLastCopyDetails &backupCopy)
{
    return false;
}

static void CheckCertThumbPrint_Stub_SUC(ActionResult &returnValue, const std::string &ip, const int32_t port,
    const std::string &thumbPrint)
{
    returnValue.code = Module::SUCCESS;
    return;
}

static bool IdentifyNasProtoVersionToUse_STUB_SUCC(uint64_t &errCode)
{
    errCode = Module::SUCCESS;
    return true;
}

static bool CreateGeneralResource_Stub_SUC(void *ob, std::string key, HetroNativeGeneral &generalInfo)
{
    return true;
}

static bool CreateScanStatsResource_Stub_SUC(void *ob, std::string key, HetroNativeScanStatistics &scanStats)
{
    return true;
}

static bool CreateBackupStatsResource_Stub_SUC(void *ob, std::string key, HetroNativeScanStatistics &scanStats)
{
    return true;
}

static void FillScanConfigBasedOnEnviroment_Stub(void *ob, ScanConfig &scanConfig)
{
    return;
}

static bool LockResource_Stub_SUC(std::string key)
{
    return true;
}

static bool UnlockResource_Stub_SUC(std::string key)
{
    return true;
}

static bool GetGeneralResource_Stub_SUC(void *ob, std::string key, HetroNativeGeneral &generalInfo)
{
    return true;
}

static bool GetScanStatsResource_Stub_SUC(void *ob, std::string key, HetroNativeScanStatistics &scanStats)
{
    return true;
}

static bool GetBackupStatsResource_Stub_SUC(void *ob, std::string key, HetroNativeScanStatistics &scanStats)
{
    return true;
}

static bool UpdateGeneralResource_Stub_SUC(void *ob, std::string key, HetroNativeGeneral &generalInfo)
{
    return true;
}

static bool UpdateScanStatsResource_Stub_SUC(void *ob, std::string key, HetroNativeScanStatistics &scanStats)
{
    return true;
}

static bool UpdateBackupResource_Stub_SUC(void *ob, std::string key, HetroNativeScanStatistics &scanStats)
{
    return true;
}

static bool DeleteGeneralResource_Stub_SUC(void *ob, std::string key)
{
    return true;
}

static bool DeleteScanStatsResource_Stub_SUC(void *ob, std::string key)
{
    return true;
}

static bool DeleteBackupStatsResource_Stub_SUC(void *ob, std::string key)
{
    return true;
}

static bool DeleteSharedResources_Stub_SUC(void *ob)
{
    return true;
}

static bool CreateGeneralResource_Stub_FAIL(void *ob, std::string key, HetroNativeGeneral &generalInfo)
{
    return false;
}

static bool CreateScanStatsResource_Stub_FAIL(void *ob, std::string key, HetroNativeScanStatistics &scanStats)
{
    return false;
}

static bool CreateBackupStatsResource_Stub_FAIL(void *ob, std::string key, HetroNativeScanStatistics &scanStats)
{
    return false;
}

static bool GetGeneralResource_Stub_FAIL(void *ob, std::string key, HetroNativeGeneral &generalInfo)
{
    return false;
}

static bool GetScanStatsResource_Stub_FAIL(void *ob, std::string key, HetroNativeScanStatistics &scanStats)
{
    return false;
}

static bool GetBackupStatsResource_Stub_FAIL(void *ob, std::string key, HetroNativeScanStatistics &scanStats)
{
    return false;
}

static bool UpdateGeneralResource_Stub_FAIL(void *ob, std::string key, HetroNativeGeneral &generalInfo)
{
    return false;
}

static bool UpdateScanStatsResource_Stub_FAIL(void *ob, std::string key, HetroNativeScanStatistics &scanStats)
{
    return false;
}

static bool UpdateBackupResource_Stub_FAIL(void *ob, std::string key, HetroNativeScanStatistics &scanStats)
{
    return false;
}

static bool DeleteGeneralResource_Stub_FAIL(void *ob, std::string key)
{
    return false;
}

static bool DeleteScanStatsResource_Stub_FAIL(void *ob, std::string key)
{
    return false;
}

static bool DeleteBackupStatsResource_Stub_FAIL(void *ob, std::string key)
{
    return false;
}

static int MountNas_Stub_SUC(void *ob, PluginUtils::NasMountParams& param, std::string &outSelectedSvcIp)
{
    std::cout << "MountNas_Stub_SUC get called" << std::endl;
    return Module::SUCCESS;
}

static int MountNas_Stub_FAIL(void *ob, PluginUtils::NasMountParams& param, std::string &outSelectedSvcIp)
{
    std::cout << "MountNas_Stub_FAIL get called" << std::endl;
    return Module::FAILED;
}

static int UnmountNas_Stub_SUC(void *ob, std::string localpath)
{
    return Module::SUCCESS;
}

static int UnmountNas_Stub_FAIL(void *ob, std::string localpath)
{
    return Module::FAILED;
}

static bool CertVerifyMgr_Stub_Fail()
{
    return false;
}

static bool CertVerifyMgr_Stub_Suc()
{
    return true;
}

static bool CreateDirectory_Stub_Fail()
{
    return false;
}

static bool CreateDirectory_Stub_Suc()
{
    return true;
}

static bool KinitTGTInner_Stub_Fail()
{
    return false;
}

static bool KinitTGTInner_Stub_Suc()
{
    return true;
}

static shared_ptr<JobCommonInfo> GetJobInfo_Stub_correct_val(void *obj)
{
    // std::cout << "111111111111111111" << endl;
    AppProtect::BackupJob backupJob = BackupJobSetup();
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    return jobInfo;
}

static void CheckCertThumbPrint_Stub_correct_val(void *obj, ActionResult &returnValue, const std::string &ip,
    const int32_t port, const std::string &thumbPrint)
{
    returnValue.code = Module::SUCCESS;
    return;
}

static shared_ptr<JobCommonInfo> GetJobInfo_Stub_bad_format_protectEnv_extendInfo(void *obj)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    backupJob.protectEnv.extendInfo = "{\"snap\":true,\"verifyStatus\":\"1\",\"wwn\":\"\",}";
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    return jobInfo;
}

static shared_ptr<JobCommonInfo> GetJobInfo_Stub_bad_format_protectObject_extendInfo(void *obj)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    backupJob.protectObject.extendInfo = "";
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    return jobInfo;
}

static shared_ptr<JobCommonInfo> GetJobInfo_Stub_bad_format_backupJob_extendInfo(void *obj)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    backupJob.extendInfo = "xyz";
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    return jobInfo;
}

static shared_ptr<JobCommonInfo> GetJobInfo_Stub_bad_repoCache_path(void *obj)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    for (auto repo : backupJob.repositories) {
        if (repo.repositoryType == RepositoryDataType::CACHE_REPOSITORY) {
            string path = "/fakePath";
            repo.path.push_back(path);
        }
    }
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));

    return jobInfo;
}

static shared_ptr<JobCommonInfo> GetJobInfo_Stub_bad_dataCache_path(void *obj)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    for (auto repo : backupJob.repositories) {
        if (repo.repositoryType == RepositoryDataType::DATA_REPOSITORY) {
            string path = "/fakePath";
            repo.path.push_back(path);
        }
    }
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    return jobInfo;
}

static shared_ptr<JobCommonInfo> GetJobInfo_Stub_CIFS(void *obj)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    backupJob.protectObject.extendInfo = "{\"authMode\":\"1\",\"filters\":\"\",\"ip\":\"10.28.12.144\""
        ",\"kerberosId\":\"0\",\"shareMode\":\"0\"}";
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    return jobInfo;
}

static shared_ptr<JobCommonInfo> GetJobInfo_Stub_Incremental(void *obj)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    backupJob.jobParam.backupType = AppProtect::BackupJobType::INCREMENT_BACKUP;
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    return jobInfo;
}

static shared_ptr<JobCommonInfo> GetJobInfo_Stub_UseSnapshot(void *obj)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    backupJob.protectEnv.extendInfo = "{\"snapConsistency\":true,\"verifyStatus\":\"1\",\"wwn\":\"\"}";
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    return jobInfo;
}

static shared_ptr<JobCommonInfo> GetJobInfo_Stub_bad_protected_managementIP(void *obj)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    backupJob.protectEnv.endpoint = "10.28.12.xxx";
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    return jobInfo;
}

static shared_ptr<JobCommonInfo> GetJobInfo_Stub_bad_protected_serviceIP(void *obj)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    backupJob.protectObject.extendInfo = "{\"authMode\":\"1\",\"filters\":\"\",\"ip\":\"10.28.12.xxx\""
        ",\"kerberosId\":\"0\",\"shareMode\":\"1\"}";
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    return jobInfo;
}

static shared_ptr<JobCommonInfo> GetJobInfo_Stub_bad_protected_Sharepath(void *obj)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    backupJob.protectObject.name = "FakePathNotPresent";
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    return jobInfo;
}

static shared_ptr<JobCommonInfo> GetJobInfo_Stub_bad_protected_Auth(void *obj)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    backupJob.protectObject.auth.authType = AuthType::APP_PASSWORD;
    backupJob.protectObject.auth.authkey = "admin";
    backupJob.protectObject.auth.authPwd = "Admin@123";
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    return jobInfo;
}

static shared_ptr<JobCommonInfo> GetJobInfo_Stub_bad_format_jobParam_advanceParams(void *obj)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    backupJob.jobParam.advanceParams = "xyz";
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    return jobInfo;
}

static shared_ptr<JobCommonInfo> GetJobInfo_Stub_bad_format_jobParam_dataLayout_extendInfo(void *obj)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    backupJob.jobParam.dataLayout.extendInfo = "xyz";
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    return jobInfo;
}

static shared_ptr<JobCommonInfo> GetJobInfo_Stub_creation_time_filter(void *obj)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    backupJob.jobParam.filters[3].filterBy = "CreateTime";
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    return jobInfo;
}

static shared_ptr<JobCommonInfo> GetJobInfo_Stub_access_time_filter(void *obj)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    backupJob.jobParam.filters[3].filterBy = "AccessTime";
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    return jobInfo;
}

static int GetConfScanLibNfsOpenDirReqCnt_STUB(void *obj)
{
    return 4000;
}

static int GetConfBackupLibNfsFhCacheDisable_STUB(void *obj)
{
    return 0;
}

static int GetConfScanExtAclDirEnabled_STUB(void *obj)
{
    return 0;
}

static int GetConfScanExtAclFileEnabled_STUB(void *obj)
{
    return 0;
}

static int GetConfScanWriteTaskInstanceCnt_STUB(void *obj)
{
    return 1;
}

static int GetConfScanThreadPoolCnt_STUB(void *obj)
{
    return 32;
}

static int GetConfScanWriteTaskStartQueueSize_STUB(void *obj)
{
    return 1000;
}

static int GetConfScanWriteTaskStopQueueSize_STUB(void *obj)
{
    return 5000;
}

static int GetConfScanUseLastBackupTime_STUB(void *obj)
{
    return 1;
}

static int GetConfIsNasRestStub_STUB(void *obj)
{
    return 0;
}
static string GetConfScanCtrlMaxDataSize_STUB(void *obj)
{
    return "5368709120";
}
static int GetConfScanCtrlFileTimeSec_STUB(void *obj)
{
    return 5;
}
static int GetConfScanCtrlMaxEntriesFullBkup_STUB(void *obj)
{
    return 10000;
}
static int GetConfScanCtrlMaxEntriesIncBkup_STUB(void *obj)
{
    return 1000;
}
static int GetConfScanDefaultMetaFileSize_STUB(void *obj)
{
    return 1048576000;
}
static int GetConfScanLibnfsDirQPopSize_STUB(void *obj)
{
    return 20;
}
static int GetConfScanLibnfsReadDirQPopSize_STUB(void *obj)
{
    return 10;
}
static int GetConfScanMaxWriteQueueSize_STUB(void *obj)
{
    return 10000;
}

static int GetConfScanMinWriteQueueSize_STUB(void *obj)
{
    return 5000;
}

static bool InitJobInfo_STUB_FAIL(void *ob)
{
    return false;
}

static bool InitJobInfo_STUB_SUCC(void *ob)
{
    return true;
}

static bool StartScanner_STUB_Suc(void *ob)
{
    return true;
}

static void PushScanConfig_STUB(void *ob)
{
    return;
}

static bool WaitToStartScanner_STUB(void *ob)
{
    return true;
}

static void StubFunction_VOID(void *ob) {}

static bool StubFunction_TRUE(void *ob)
{
    return true;
}

static bool MonitorScanner_STUB_Suc(void *ob, SCANNER_TASK_STATUS &scanTaskStatus, SubJobStatus::type &jobStatus,
    std::string &jobLogStr, int &jobProgress)
{
    return true;
}

static void ReportJobDetails_Stub(void *ob, ActionResult &returnValue, const SubJobDetails &jobInfo)
{
    return;
}

static void ReportCopyAdditionalInfo_Stub(void *ob, ActionResult& returnValue, const std::string& jobId, const Copy& copy)
{
    returnValue.code = Module::SUCCESS;
    return;
}

static bool SnapshotNameResource_Stub(std::string key)
{
    return true;
}

static bool CheckRemoteNasMount_Stub(std::string proto, std::string protoVersion, ProtectedNasShare &m_nasShare,
    std::string m_tempLocalMountPath)
{
    return true;
}

static int ConfigReaderGetInt_Stub(void *ob, const string& sectionName, const string& keyName, bool logFlag = true)
{
    return 1;
}

static bool CheckDataFsMount_Stub(std::string proto, std::string protoVersion, StorageRepository &m_dataFs,
    std::string m_dataFsSvcIp, ProtectedNasShare &m_nasShare)
{
    return true;
}

static void returnVoidStub(void* obj)
{
    return;
}

static bool checkFilePathAndGetSrcFileList_Stub_Suc()
{
    return true;
}

static bool StubOperateIpsRule(std::vector<std::string>& ipList, const std::string& operation)
{
    return true;
}

void HetroBackupJobTest::SetUp()
{
    m_hetroBackupJobObj = std::make_unique<HetroBackupJob>();
    SubJob subJob;
    // subJobId keyword is optional, this operation is necessary
    subJob.__isset.subJobId = true;
    subJob.__set_jobId("sub_job_id");
    subJob.jobId = "jobId123";
    subJob.subJobId = "subJob123";
    subJob.jobName = "XYZ";
    subJob.jobPriority = 1;
    subJob.jobInfo = "{\"ControlFile\":\"\",\"SubTaskType\":1,\"Ext\":\"\"}";
    std::shared_ptr<SubJob> subJobptr = std::make_shared<SubJob>(subJob);
    m_hetroBackupJobObj->SetSubJob(subJobptr);

    stub.set(sleep, returnVoidStub);
    stub.set(ADDR(HetroBackupJob, FillScanConfigBasedOnEnviroment), FillScanConfigBasedOnEnviroment_Stub);
    stub.set(ADDR(JobService, ReportJobDetails), ReportJobDetails_Stub);
    stub.set(ADDR(JobService, QueryPreviousCopy), returnVoidStub);
    stub.set(ADDR(HetroCommonService, CreateGeneralResource), CreateGeneralResource_Stub_SUC);
    stub.set(ADDR(HetroCommonService, CreateScanStatsResource), CreateScanStatsResource_Stub_SUC);
    stub.set(ADDR(HetroCommonService, CreateBackupStatsResource), CreateBackupStatsResource_Stub_SUC);
    stub.set(ADDR(HetroCommonService, LockResource), LockResource_Stub_SUC);
    stub.set(ADDR(HetroCommonService, UnlockResource), UnlockResource_Stub_SUC);
    stub.set(ADDR(HetroCommonService, GetGeneralResource), GetGeneralResource_Stub_SUC);
    stub.set(ADDR(HetroCommonService, GetScanStatsResource), GetScanStatsResource_Stub_SUC);
    stub.set(ADDR(HetroCommonService, GetBackupStatsResource), GetBackupStatsResource_Stub_SUC);
    stub.set(ADDR(HetroCommonService, UpdateGeneralResource), UpdateGeneralResource_Stub_SUC);
    stub.set(ADDR(HetroCommonService, UpdateScanStatsResource), UpdateScanStatsResource_Stub_SUC);
    stub.set(ADDR(HetroCommonService, UpdateBackupStatsResource), UpdateBackupResource_Stub_SUC);
    stub.set(ADDR(HetroCommonService, DeleteGeneralResource), DeleteGeneralResource_Stub_SUC);

    stub.set(ADDR(HetroCommonService, DeleteScanStatsResource), DeleteScanStatsResource_Stub_SUC);
    stub.set(ADDR(HetroCommonService, DeleteBackupStatsResource), DeleteBackupStatsResource_Stub_SUC);
    stub.set(ADDR(HetroCommonService, checkFilePathAndGetSrcFileList), checkFilePathAndGetSrcFileList_Stub_Suc);
    // stub.set(ADDR(BasicJob, GetJobInfo), GetJobInfo_Stub_correct_val);
    stub.set(ADDR(ScanMgr, Initiate), Initiate_Stub_Succ);
    stub.set(ADDR(ScanMgr, StartScan), StartScan_Stub_Succ);
    stub.set(ADDR(ScanMgr, AbortScan), AbortScan_Stub_Succ);
    stub.set(ADDR(ScanMgr, Destroy), Destroy_Stub);
    stub.set(ADDR(ScanMgr, Enqueue), Enqueue_Stub);
    stub.set(ADDR(ScanMgr, GetScanStatus), GetScanStatus_Stub_Completed);
    stub.set(ADDR(ScanMgr, GetScanStats), GetScanStats_Stub);
    stub.set(ADDR(SecurityService, CheckCertThumbPrint), CheckCertThumbPrint_Stub_correct_val);
    stub.set(ADDR(JobService, ReportCopyAdditionalInfo), ReportCopyAdditionalInfo_Stub);
    stub.set(ADDR(JobService, AddNewJob), returnVoidStub);
    stub.set(ADDR(ConfigReader, getInt), ConfigReaderGetInt_Stub);
    // stub.set(ADDR(HetroCommonService, FillScanConfigForNative), returnVoidStub);
    stub.set(ADDR(HetroCommonService, DeleteSharedResources), DeleteSharedResources_Stub_SUC);
    stub.set(ADDR(PluginUtils, OperateIpsRule), StubOperateIpsRule);

    m_hetroBackupJobObj->m_cacheFsPath = "/MetaFS";
}

void HetroBackupJobTest::TearDown()
{
    stub.reset(sleep);
    stub.reset(ADDR(JobService, ReportJobDetails));
    stub.reset(ADDR(JobService, QueryPreviousCopy));
    stub.reset(ADDR(HetroBackupJob, FillScanConfigBasedOnEnviroment));
    stub.reset(ADDR(HetroCommonService, CreateGeneralResource));
    stub.reset(ADDR(HetroCommonService, CreateScanStatsResource));
    stub.reset(ADDR(HetroCommonService, CreateBackupStatsResource));
    stub.reset(ADDR(HetroCommonService, LockResource));
    stub.reset(ADDR(HetroCommonService, UnlockResource));
    stub.reset(ADDR(HetroCommonService, GetGeneralResource));
    stub.reset(ADDR(HetroCommonService, GetScanStatsResource));
    stub.reset(ADDR(HetroCommonService, GetBackupStatsResource));
    stub.reset(ADDR(HetroCommonService, UpdateGeneralResource));
    stub.reset(ADDR(HetroCommonService, UpdateScanStatsResource));
    stub.reset(ADDR(HetroCommonService, UpdateBackupStatsResource));
    stub.reset(ADDR(HetroCommonService, DeleteGeneralResource));
    stub.reset(ADDR(HetroCommonService, DeleteScanStatsResource));
    stub.reset(ADDR(HetroCommonService, DeleteBackupStatsResource));
    stub.reset(ADDR(ScanMgr, Initiate));
    stub.reset(ADDR(ScanMgr, StartScan));
    stub.reset(ADDR(ScanMgr, AbortScan));
    stub.reset(ADDR(ScanMgr, Destroy));
    stub.reset(ADDR(ScanMgr, Enqueue));
    stub.reset(ADDR(ScanMgr, GetScanStatus));
    stub.reset(ADDR(ScanMgr, GetScanStats));
    // stub.reset(ADDR(SecurityService, CheckCertThumbPrint));
    // stub.reset(ADDR(BasicJob, GetJobInfo));
}

void HetroBackupJobTest::SetUpTestCase() {}

void HetroBackupJobTest::TearDownTestCase() {}

static bool UpdateScanStatsResource_Stub(std::string key, HetroNativeScanStatistics &scanStats)
{
    return true;
}

static void PrintSubJobInfo_Stub(std::shared_ptr<SubJob> &m_subJobInfo)
{
    return;
}

static bool IsAggregate_Stub_True(void *obj)
{
    return true;
}

static bool CreateSubTask_Stub_True(void *obj, const SubJob &subJob)
{
    return true;
}


static bool CreateBackupJobTeardownTask_Stub_True(void *obj)
{
    return true;
}

static bool CreateBackupCopyMetaTask_Stub_True(void *obj)
{
    return true;
}

static bool CheckSmbConnectVersion_Stub_True(void *obj, Module::SmbVersion version, uint64_t &errCode)
{
    return true;
}

auto SetSubJobInfo(string SubTaskType)
{
    SubJob subJob;
    // subJobId keyword is optional, this operation is necessary
    subJob.__isset.subJobId = true;
    subJob.__set_jobId("sub_job_id");
    subJob.jobId = "jobId123";
    subJob.subJobId = "subJob123";
    subJob.jobName = "XYZ";
    subJob.jobPriority = 1;
    if (SubTaskType == "TEARDOWN") {
        subJob.jobInfo = "{\"ControlFile\":\"\",\"SubTaskType\":5,\"Ext\":\"\"}";
    } else if (SubTaskType == "COPYMETA") {
        subJob.jobInfo = "{\"ControlFile\":\"\",\"SubTaskType\":6,\"Ext\":\"\"}";
    } else {
        subJob.jobInfo = "{\"ControlFile\":\"\",\"SubTaskType\":1,\"Ext\":\"\"}";
    }

    std::shared_ptr<SubJob> subJobptr = std::make_shared<SubJob>(subJob);
    return subJobptr;
}

/*
 * 用例名称:检查前置任务流程
 * 前置条件：无
 * check点：检查前置任务流程顺利运行
 */
// TEST_F(HetroBackupJobTest, CheckPrerequisiteJob)
// {
//     AppProtect::BackupJob backupJob = BackupJobSetup();
//     std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
//     m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
//     stub.set(ADDR(HetroCommonService, CheckRemoteNasMount), CheckRemoteNasMount_Stub);
//     stub.set(ADDR(HetroCommonService, CheckDataFsMount), CheckDataFsMount_Stub);
//     EXPECT_EQ(m_hetroBackupJobObj->PrerequisiteJob(), Module::SUCCESS);
//     stub.reset(ADDR(HetroCommonService, CheckRemoteNasMount));
//     stub.reset(ADDR(HetroCommonService, CheckDataFsMount));

//     m_hetroBackupJobObj->m_jobCommonInfo = nullptr;
//     m_hetroBackupJobObj->m_backupJobPtr = nullptr;
//     EXPECT_EQ(m_hetroBackupJobObj->PrerequisiteJob(), Module::FAILED);
// }

/*
 * 用例名称:检查生成子任务流程
 * 前置条件：无
 * check点：检查生成子任务流程顺利运行
 */
// TEST_F(HetroBackupJobTest, CheckGenerateSubJob)
// {
//     AppProtect::BackupJob backupJob = BackupJobSetup();
//     std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
//     m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
//     EXPECT_EQ(m_hetroBackupJobObj->GenerateSubJob(), Module::SUCCESS);
// }

/*
 * 用例名称:检查生成子任务流程
 * 前置条件：无
 * check点：检查生成子任务流程顺利运行
 */
// TEST_F(HetroBackupJobTest, CheckGenerateSubJobTeardown)
// {
//     AppProtect::BackupJob backupJob = BackupJobSetup();
//     std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
//     m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
//     // stub.set((bool(*)(const SubJob&))ADDR(HetroCommonService, CreateSubTask), CreateSubTask_Stub_True);
//     stub.set(ADDR(HetroBackupJob, CreateBackupJobTeardownTask), CreateBackupJobTeardownTask_Stub_True);
//     EXPECT_EQ(m_hetroBackupJobObj->GenerateSubJob(), Module::SUCCESS);
//     // stub.reset(ADDR(HetroCommonService, CreateSubTask));
//     stub.reset(ADDR(HetroBackupJob, CreateBackupJobTeardownTask));
// }

/*
 * 用例名称:检查生成子任务流程
 * 前置条件：无
 * check点：检查生成子任务流程顺利运行
 */
// TEST_F(HetroBackupJobTest, CheckGenerateSubJobCopyMeta)
// {
//     AppProtect::BackupJob backupJob = BackupJobSetup();
//     std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
//     m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
//     stub.set(ADDR(HetroBackupJob, CreateBackupJobTeardownTask), CreateBackupJobTeardownTask_Stub_True);
//     stub.set(ADDR(HetroBackupJob, CreateBackupCopyMetaTask), CreateBackupCopyMetaTask_Stub_True);
//     EXPECT_EQ(m_hetroBackupJobObj->GenerateSubJob(), Module::SUCCESS);
//     stub.reset(ADDR(HetroBackupJob, CreateBackupJobTeardownTask));
//     stub.reset(ADDR(HetroBackupJob, CreateBackupJobTeardownTask));
// }

/*
 * 用例名称:检查执行子任务流程
 * 前置条件：无
 * check点：检查执行子任务流程顺利运行
 */
TEST_F(HetroBackupJobTest, CheckExecuteSubJob)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    stub.set(ADDR(HetroCommonService, PrintSubJobInfo), PrintSubJobInfo_Stub);
    stub.set(ADDR(FS_Backup::BackupMgr, CreateBackupInst), CreateBackupInstStub_Succ);
    EXPECT_EQ(m_hetroBackupJobObj->ExecuteSubJob(), Module::SUCCESS);
    stub.reset(ADDR(HetroCommonService, PrintSubJobInfo));
    stub.reset(ADDR(FS_Backup::BackupMgr, CreateBackupInst));
}

/*
 * 用例名称:检查执行子任务流程
 * 前置条件：无
 * check点：检查执行子任务流程顺利运行
 */
TEST_F(HetroBackupJobTest, CheckExecuteSubJobAggregate)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    backupJob.extendInfo = "{\"auto_index\":\"false\",\"permissions_and_attributes\":\"0\",\"proxy_host_mode\":\"0\","
        "\"small_file_aggregation\":\"0\", \"aggregation_file_size\":\"222\",\"aggregation_file_max_size\":\"22\"}";
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    stub.set(ADDR(HetroCommonService, PrintSubJobInfo), PrintSubJobInfo_Stub);
    stub.set(ADDR(FS_Backup::BackupMgr, CreateBackupInst), CreateBackupInstStub_Succ);
    stub.set(ADDR(HetroBackupJob, IsAggregate), IsAggregate_Stub_True);
    EXPECT_EQ(m_hetroBackupJobObj->ExecuteSubJob(), Module::SUCCESS);
    stub.reset(ADDR(HetroCommonService, PrintSubJobInfo));
    stub.reset(ADDR(FS_Backup::BackupMgr, CreateBackupInst));
    stub.reset(ADDR(HetroBackupJob, IsAggregate));
}

/*
 * 用例名称:检查执行子任务流程
 * 前置条件：无
 * check点：检查执行子任务流程顺利运行
 */
TEST_F(HetroBackupJobTest, CheckExecuteSubJobCifs)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    backupJob.protectObject.extendInfo = "{\"authMode\":\"1\",\"filters\":\"\",\"ip\":\"10.28.12.144\""
        ",\"kerberosId\":\"0\",\"shareMode\":\"0\"}";
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    m_hetroBackupJobObj->m_nasShare.nasShareExt.m_protocol = "0";
    stub.set(ADDR(HetroCommonService, PrintSubJobInfo), PrintSubJobInfo_Stub);
    stub.set(ADDR(FS_Backup::BackupMgr, CreateBackupInst), CreateBackupInstStub_Succ);
    stub.set(ADDR(HetroBackupJob, CheckSmbConnectVersion), CheckSmbConnectVersion_Stub_True);
    EXPECT_EQ(m_hetroBackupJobObj->ExecuteSubJob(), Module::SUCCESS);
    stub.reset(ADDR(HetroCommonService, PrintSubJobInfo));
    stub.reset(ADDR(FS_Backup::BackupMgr, CreateBackupInst));
    stub.reset(ADDR(HetroBackupJob, CheckSmbConnectVersion));
}

/*
 * 用例名称:检查执行子任务流程
 * 前置条件：无
 * check点：检查执行子任务流程顺利运行
 */
TEST_F(HetroBackupJobTest, CheckExecuteSubJobGetJobInfoSuc)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    m_hetroBackupJobObj->m_backupJobPtr = nullptr;
    stub.set(ADDR(HetroCommonService, PrintSubJobInfo), PrintSubJobInfo_Stub);
    stub.set(ADDR(FS_Backup::BackupMgr, CreateBackupInst), CreateBackupInstStub_Succ);
    stub.set(ADDR(HetroBackupJob, CheckSmbConnectVersion), CheckSmbConnectVersion_Stub_True);
    EXPECT_EQ(m_hetroBackupJobObj->ExecuteSubJob(), Module::SUCCESS);
    stub.reset(ADDR(HetroCommonService, PrintSubJobInfo));
    stub.reset(ADDR(FS_Backup::BackupMgr, CreateBackupInst));
    stub.reset(ADDR(HetroBackupJob, CheckSmbConnectVersion));
}

/*
 * 用例名称:检查执行子任务流程
 * 前置条件：无
 * check点：检查执行子任务流程顺利运行
 */
// TEST_F(HetroBackupJobTest, CheckExecuteSubJobTeardown)
// {
//     AppProtect::BackupJob backupJob = BackupJobSetup();
//     std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
//     m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
//     // m_hetroBackupJobObj.m_nasShare.nasShareExt.m_protocol = "0";
//     m_hetroBackupJobObj->SetSubJob(SetSubJobInfo("TEARDOWN"));
//     stub.set(ADDR(HetroCommonService, PrintSubJobInfo), PrintSubJobInfo_Stub);
//     stub.set(ADDR(FS_Backup::BackupMgr, CreateBackupInst), CreateBackupInstStub_Succ);
//     EXPECT_EQ(m_hetroBackupJobObj->ExecuteSubJob(), Module::SUCCESS);
//     stub.reset(ADDR(HetroCommonService, PrintSubJobInfo));
//     stub.reset(ADDR(FS_Backup::BackupMgr, CreateBackupInst));
// }

/*
 * 用例名称:检查执行子任务流程
 * 前置条件：无
 * check点：检查执行子任务流程顺利运行
 */
TEST_F(HetroBackupJobTest, CheckExecuteSubJobCopyMeta)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    m_hetroBackupJobObj->SetSubJob(SetSubJobInfo("COPYMETA"));
    stub.set(ADDR(HetroCommonService, PrintSubJobInfo), PrintSubJobInfo_Stub);
    stub.set(ADDR(FS_Backup::BackupMgr, CreateBackupInst), CreateBackupInstStub_Succ);
    stub.set(ADDR(HetroBackupJob, ExecuteCopyMetaSubJobInner), ExecuteCopyMetaSubJobInner_Stub);
    EXPECT_EQ(m_hetroBackupJobObj->ExecuteSubJob(), Module::SUCCESS);
    stub.reset(ADDR(HetroCommonService, PrintSubJobInfo));
    stub.reset(ADDR(FS_Backup::BackupMgr, CreateBackupInst));
    stub.reset(ADDR(HetroBackupJob, ExecuteCopyMetaSubJobInner));
}

/*
 * 用例名称:检查执行子任务流程
 * 前置条件：无
 * check点：检查执行子任务流程顺利运行
 */
TEST_F(HetroBackupJobTest, CheckExecuteSubJobStatusFailed)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    stub.set(ADDR(HetroCommonService, PrintSubJobInfo), PrintSubJobInfo_Stub);
    stub.set(ADDR(FS_Backup::BackupMgr, CreateBackupInst), CreateBackupInstStub_Failed);
    EXPECT_EQ(m_hetroBackupJobObj->ExecuteSubJob(), Module::SUCCESS);
    stub.reset(ADDR(HetroCommonService, PrintSubJobInfo));
    stub.reset(ADDR(FS_Backup::BackupMgr, CreateBackupInst));
}

/*
 * 用例名称:检查执行子任务流程
 * 前置条件：无
 * check点：检查执行子任务流程顺利运行
 */
TEST_F(HetroBackupJobTest, CheckExecuteSubJobStatusAborted)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    stub.set(ADDR(HetroCommonService, PrintSubJobInfo), PrintSubJobInfo_Stub);
    stub.set(ADDR(FS_Backup::BackupMgr, CreateBackupInst), CreateBackupInstStub_Aborted);
    EXPECT_EQ(m_hetroBackupJobObj->ExecuteSubJob(), Module::SUCCESS);
    stub.reset(ADDR(HetroCommonService, PrintSubJobInfo));
    stub.reset(ADDR(FS_Backup::BackupMgr, CreateBackupInst));
}

static bool IsAbortJob_Stub_True()
{
    return true;
}

/*
 * 用例名称:检查执行子任务流程
 * 前置条件：无
 * check点：检查执行子任务流程顺利运行
 */
TEST_F(HetroBackupJobTest, CheckExecuteSubJobStatusAbortJob)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    stub.set(ADDR(BasicJob, IsAbortJob), IsAbortJob_Stub_True);
    stub.set(ADDR(HetroCommonService, PrintSubJobInfo), PrintSubJobInfo_Stub);
    stub.set(ADDR(FS_Backup::BackupMgr, CreateBackupInst), CreateBackupInstStub_Succ);
    EXPECT_EQ(m_hetroBackupJobObj->ExecuteSubJob(), Module::SUCCESS);
    stub.reset(ADDR(BasicJob, IsAbortJob));
    stub.reset(ADDR(HetroCommonService, PrintSubJobInfo));
    stub.reset(ADDR(FS_Backup::BackupMgr, CreateBackupInst));
}

/*
 * 用例名称:检查后置任务流程
 * 前置条件：无
 * check点：检查后置任务流程顺利运行
 */
TEST_F(HetroBackupJobTest, CheckPostJob)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    EXPECT_EQ(m_hetroBackupJobObj->PostJob(), Module::SUCCESS);
}

/*
 * 用例名称:检查非聚合场景下后置任务流程
 * 前置条件：无
 * check点：检查后置任务流程顺利运行
 */
TEST_F(HetroBackupJobTest, CheckPostJobAggregate)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    stub.set(ADDR(HetroBackupJob, IsAggregate), IsAggregate_Stub_True);
    EXPECT_EQ(m_hetroBackupJobObj->PostJob(), Module::SUCCESS);
    stub.reset(ADDR(HetroBackupJob, IsAggregate));
}

/*
 * 用例名称：CheckReportJobProgress
 * 前置条件：无
 * check点：根据m_backupStatus不同进入不同状态的分支
 */
TEST_F(HetroBackupJobTest, CheckReportJobProgress)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;

    std::string jobLogLabel = "nas_plugin_hetro_backup_data_fail_label";
    SubJobStatus::type jobStatus = SubJobStatus::COMPLETED;
    m_hetroBackupJobObj->ReportJobProgress(jobStatus, jobLogLabel);

    jobStatus = SubJobStatus::RUNNING;
    m_hetroBackupJobObj->m_backupStatus = BackupPhaseStatus::FAILED_NOACCESS;
    EXPECT_NO_THROW(m_hetroBackupJobObj->ReportJobProgress(jobStatus, jobLogLabel));

    m_hetroBackupJobObj->m_backupStatus = BackupPhaseStatus::FAILED_NOSPACE;
    EXPECT_NO_THROW(m_hetroBackupJobObj->ReportJobProgress(jobStatus, jobLogLabel));

    m_hetroBackupJobObj->m_backupStatus = BackupPhaseStatus::FAILED_PROT_SERVER_NOTREACHABLE;
    EXPECT_NO_THROW(m_hetroBackupJobObj->ReportJobProgress(jobStatus, jobLogLabel));

    m_hetroBackupJobObj->m_backupStatus = BackupPhaseStatus::FAILED_SEC_SERVER_NOTREACHABLE;
    EXPECT_NO_THROW(m_hetroBackupJobObj->ReportJobProgress(jobStatus, jobLogLabel));

    m_hetroBackupJobObj->m_backupStatus = BackupPhaseStatus::FAILED;
    EXPECT_NO_THROW(m_hetroBackupJobObj->ReportJobProgress(jobStatus, jobLogLabel));
}

/*
 * 用例名称: CheckFillMonitorScannerVarDetails
 * 前置条件：
 * check点：根据m_scanStatus不同状态返回对应值
 */
TEST_F(HetroBackupJobTest, CheckFillMonitorScannerVarDetails)
{
    auto obj_index = std::make_unique<HetroBackupJob>();
    HetroBackupJob::SCANNER_TASK_STATUS scanTaskStatus =
        HetroBackupJob::SCANNER_TASK_STATUS::SCANNER_TASK_STATUS_SUCCESS;
    SubJobStatus::type jobStatus = SubJobStatus::COMPLETED;
    std::string jobLogLabel = "nas_plugin_hetro_backup_scan_completed_label";
    constexpr uint32_t PROGRESS100 = 100;
    int jobProgress = PROGRESS100;
    obj_index->m_scanStatus = SCANNER_STATUS::FAILED;
    obj_index->FillMonitorScannerVarDetails(scanTaskStatus, jobStatus, jobLogLabel, jobProgress);
    EXPECT_EQ(jobStatus, SubJobStatus::FAILED);

    obj_index->m_scanStatus = SCANNER_STATUS::ABORT_IN_PROGRESS;
    obj_index->FillMonitorScannerVarDetails(scanTaskStatus, jobStatus, jobLogLabel, jobProgress);
    EXPECT_EQ(jobStatus, SubJobStatus::ABORTING);

    obj_index->m_scanStatus = SCANNER_STATUS::ABORTED;
    obj_index->FillMonitorScannerVarDetails(scanTaskStatus, jobStatus, jobLogLabel, jobProgress);
    EXPECT_EQ(jobStatus, SubJobStatus::ABORTED);

    obj_index->m_scanStatus = SCANNER_STATUS::SCAN_READ_COMPLETED;
    obj_index->FillMonitorScannerVarDetails(scanTaskStatus, jobStatus, jobLogLabel, jobProgress);
    EXPECT_EQ(jobStatus, SubJobStatus::RUNNING);

    obj_index->m_scanStatus = SCANNER_STATUS::CTRL_DIFF_IN_PROGRESS;
    obj_index->FillMonitorScannerVarDetails(scanTaskStatus, jobStatus, jobLogLabel, jobProgress);
    EXPECT_EQ(jobStatus, SubJobStatus::RUNNING);

    obj_index->m_scanStatus = SCANNER_STATUS::SECONDARY_SERVER_NOT_REACHABLE;
    obj_index->FillMonitorScannerVarDetails(scanTaskStatus, jobStatus, jobLogLabel, jobProgress);
    EXPECT_EQ(jobStatus, SubJobStatus::FAILED);

    obj_index->m_scanStatus = SCANNER_STATUS::PROTECTED_SERVER_NOT_REACHABLE;
    obj_index->FillMonitorScannerVarDetails(scanTaskStatus, jobStatus, jobLogLabel, jobProgress);
    EXPECT_EQ(jobStatus, SubJobStatus::FAILED);

    obj_index->m_scanStatus = SCANNER_STATUS::ERROR_INC_TO_FULL;
    obj_index->FillMonitorScannerVarDetails(scanTaskStatus, jobStatus, jobLogLabel, jobProgress);
    EXPECT_EQ(jobStatus, SubJobStatus::FAILED);
}

/*
 * 用例名称:CheckFillSnapDiffScanConfig
 * 前置条件：无
 * check点：检查FillSnapDiffScanConfig顺利运行
 */
TEST_F(HetroBackupJobTest, CheckFillSnapDiffScanConfig)
{
    ScanConfig scanConfig {};
    EXPECT_NO_THROW(m_hetroBackupJobObj->FillSnapDiffScanConfig(scanConfig));
}

/*
 * 用例名称: CheckScannerCtrlFileCallBack
 * 前置条件：
 * check点：ScannerCtrlFileCallBack正常调用
 */
TEST_F(HetroBackupJobTest, CheckScannerCtrlFileCallBack)
{
    void *usrData = 0;
    string controlFilePath = "1.txt";
    EXPECT_NO_THROW(m_hetroBackupJobObj->ScannerCtrlFileCallBack(usrData, controlFilePath));
}

/*
 * 用例名称: CheckScannerHardLinkCallBack
 * 前置条件：
 * check点：ScannerHardLinkCallBack正常调用
 */
TEST_F(HetroBackupJobTest, CheckScannerHardLinkCallBack)
{
    void *usrData = 0;
    string controlFilePath = "1.txt";
    EXPECT_NO_THROW(m_hetroBackupJobObj->ScannerHardLinkCallBack(usrData, controlFilePath));
}

/*
 * 用例名称: CheckBackupDirMTimeCallBack
 * 前置条件：
 * check点：BackupDirMTimeCallBack正常调用
 */
TEST_F(HetroBackupJobTest, CheckBackupDirMTimeCallBack)
{
    void *usrData = 0;
    string controlFilePath = "1.txt";
    EXPECT_NO_THROW(m_hetroBackupJobObj->BackupDirMTimeCallBack(usrData, controlFilePath));
}

/*
 * 用例名称: CheckBackupDelCtrlCallBack
 * 前置条件：
 * check点：BackupDelCtrlCallBack正常调用
 */
TEST_F(HetroBackupJobTest, CheckBackupDelCtrlCallBack)
{
    void *usrData = 0;
    string controlFilePath = "1.txt";
    EXPECT_NO_THROW(m_hetroBackupJobObj->BackupDelCtrlCallBack(usrData, controlFilePath));
}


TEST_F(HetroBackupJobTest, GetAggCopyExtendInfo)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    m_hetroBackupJobObj->GetBackupJobInfo();
    m_hetroBackupJobObj->m_backupJobPtr->copy.id = "12345";
    m_hetroBackupJobObj->m_aggrInfo.m_maxSizeToAggregate = "128";
    m_hetroBackupJobObj->m_aggrInfo.m_maxSizeAfterAggregate = "256";
    m_hetroBackupJobObj->m_aggrInfo.m_isAggregate = "2";
    std::string extendInfo;
    bool result = m_hetroBackupJobObj->GetAggCopyExtendInfo(extendInfo);
    EXPECT_EQ(result, true);
}

TEST_F(HetroBackupJobTest, GetNativeCopyExtendInfo)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    m_hetroBackupJobObj->GetBackupJobInfo();
    m_hetroBackupJobObj->m_backupJobPtr->copy.id = "12345";
    m_hetroBackupJobObj->m_aggrInfo.m_maxSizeToAggregate = "0";
    m_hetroBackupJobObj->m_aggrInfo.m_maxSizeAfterAggregate = "0";
    m_hetroBackupJobObj->m_aggrInfo.m_isAggregate = "1";
    std::string extendInfo;
    bool result = m_hetroBackupJobObj->GetAggCopyExtendInfo(extendInfo);
    EXPECT_EQ(result, true);

}

TEST_F(HetroBackupJobTest, PostReportCopyAdditionalInfo)
{
    stub.set(ADDR(JobService, ReportCopyAdditionalInfo), ReportCopyAdditionalInfo_Stub);
    AppProtect::BackupJob backupJob = BackupJobSetup();
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    m_hetroBackupJobObj->GetBackupJobInfo();
    m_hetroBackupJobObj->m_backupJobPtr->copy.id = "1234abcd";
    m_hetroBackupJobObj->m_aggrInfo.m_maxSizeToAggregate = "128";
    m_hetroBackupJobObj->m_aggrInfo.m_maxSizeAfterAggregate = "256";
    m_hetroBackupJobObj->m_aggrInfo.m_isAggregate = "2";
    m_hetroBackupJobObj->m_jobResult = AppProtect::JobResult::type::SUCCESS;
    EXPECT_EQ( m_hetroBackupJobObj->PostReportCopyAdditionalInfo(), true);
}


/*
 * 用例名称: InitJobInfo
 * 前置条件：无
 * check点：初始化JoboInfo函数分支场景
 */
// TEST_F(HetroBackupJobTest, InitJobInfo)
// {
//     AppProtect::BackupJob backupJob = BackupJobSetup();
//     std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
//     m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
//     m_hetroBackupJobObj->GetBackupJobInfo();
//     m_hetroBackupJobObj->m_backupJobPtr->protectEnv.extendInfo = "test";
//     EXPECT_EQ(m_hetroBackupJobObj->InitJobInfo(), false);

//     backupJob = BackupJobSetup();
//     jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
//     m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
//     m_hetroBackupJobObj->GetBackupJobInfo();
//     m_hetroBackupJobObj->m_backupJobPtr->protectEnv.extendInfo =
//         "{\"snapConsistency\":true,\"verifyStatus\":\"1\",\"wwn\":\"\"}";
//     stub.set(ADDR(HetroCommonService, CertVerifyMgr), CertVerifyMgr_Stub_Fail);
//     EXPECT_EQ(m_hetroBackupJobObj->InitJobInfo(), false);
//     stub.reset(ADDR(HetroCommonService, CertVerifyMgr));

//     backupJob = BackupJobSetup();
//     jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
//     m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
//     m_hetroBackupJobObj->GetBackupJobInfo();
//     m_hetroBackupJobObj->m_backupJobPtr->protectEnv.extendInfo =
//         "{\"snapConsistency\":true,\"verifyStatus\":\"1\",\"wwn\":\"\"}";
//     m_hetroBackupJobObj->m_backupJobPtr->protectObject.extendInfo = "";
//     EXPECT_EQ(m_hetroBackupJobObj->InitJobInfo(), false);

//     backupJob = BackupJobSetup();
//     jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
//     m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
//     m_hetroBackupJobObj->GetBackupJobInfo();
//     m_hetroBackupJobObj->m_backupJobPtr->protectEnv.extendInfo =
//         "{\"snapConsistency\":true,\"verifyStatus\":\"1\",\"wwn\":\"\"}";
//     m_hetroBackupJobObj->m_backupJobPtr->protectObject.extendInfo = "{\"ip\":\"127.0.0.1\"}";
//     m_hetroBackupJobObj->m_backupJobPtr->extendInfo = "";
//     EXPECT_EQ(m_hetroBackupJobObj->InitJobInfo(), false);

//     backupJob = BackupJobSetup();
//     jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
//     m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
//     m_hetroBackupJobObj->GetBackupJobInfo();
//     m_hetroBackupJobObj->m_backupJobPtr->protectEnv.extendInfo =
//         "{\"snapConsistency\":true,\"verifyStatus\":\"1\",\"wwn\":\"\"}";
//     m_hetroBackupJobObj->m_backupJobPtr->protectObject.extendInfo = "{\"ip\":\"127.0.0.1\"}";
//     m_hetroBackupJobObj->m_backupJobPtr->extendInfo =
//         "{\"small_file_aggregation\":\"1\", \"aggregation_file_size\":\"10\", \"aggregation_file_max_size\":\"20\"}";
//     EXPECT_EQ(m_hetroBackupJobObj->InitJobInfo(), true);

//     backupJob = BackupJobSetup();
//     jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
//     m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
//     m_hetroBackupJobObj->GetBackupJobInfo();
//     m_hetroBackupJobObj->m_backupJobPtr->protectEnv.extendInfo =
//         "{\"snapConsistency\":true,\"verifyStatus\":\"1\",\"wwn\":\"\"}";
//     m_hetroBackupJobObj->m_backupJobPtr->protectObject.extendInfo = "{\"ip\":\"127.0.0.1\"}";
//     m_hetroBackupJobObj->m_backupJobPtr->extendInfo = "{\"auto_index\":\"1\"}";
//     EXPECT_EQ(m_hetroBackupJobObj->InitJobInfo(), true);

//     backupJob = BackupJobSetup();
//     jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
//     m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
//     m_hetroBackupJobObj->GetBackupJobInfo();
//     m_hetroBackupJobObj->m_backupJobPtr->protectEnv.extendInfo =
//         "{\"snapConsistency\":true,\"verifyStatus\":\"1\",\"wwn\":\"\"}";
//     m_hetroBackupJobObj->m_backupJobPtr->protectObject.extendInfo = "{\"ip\":\"127.0.0.1\"}";
//     m_hetroBackupJobObj->m_backupJobPtr->extendInfo = "{\"auto_index\":\"1\"}";
//     stub.set(PluginUtils::CreateDirectory, CreateDirectory_Stub_Fail);
//     EXPECT_EQ(m_hetroBackupJobObj->InitJobInfo(), false);
//     stub.reset(PluginUtils::CreateDirectory);

//     backupJob = BackupJobSetup();
//     jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
//     m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
//     m_hetroBackupJobObj->GetBackupJobInfo();
//     m_hetroBackupJobObj->m_backupJobPtr->protectEnv.extendInfo =
//         "{\"snapConsistency\":true,\"verifyStatus\":\"1\",\"wwn\":\"\"}";
//     m_hetroBackupJobObj->m_backupJobPtr->protectObject.extendInfo = "{\"ip\":\"127.0.0.1\"}";
//     m_hetroBackupJobObj->m_backupJobPtr->extendInfo = "{}";
//     m_hetroBackupJobObj->m_metaFs.path.clear();
//     m_hetroBackupJobObj->m_backupJobPtr->repositories.clear();
//     stub.set(PluginUtils::CreateDirectory, CreateDirectory_Stub_Suc);
//     EXPECT_EQ(m_hetroBackupJobObj->InitJobInfo(), false);
//     stub.reset(PluginUtils::CreateDirectory);


//     backupJob = BackupJobSetup();
//     jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
//     m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
//     m_hetroBackupJobObj->GetBackupJobInfo();
//     m_hetroBackupJobObj->m_nasShare.nasShareExt.m_protocol = NAS_PROTOCOL_TYPE_E_NFS;
//     auto it = m_hetroBackupJobObj->m_backupJobPtr->repositories.begin();
//     auto itEnd = m_hetroBackupJobObj->m_backupJobPtr->repositories.end();
//     while (it != itEnd) {
//         if (it->repositoryType == RepositoryDataType::DATA_REPOSITORY) {
//             m_hetroBackupJobObj->m_backupJobPtr->repositories.erase(it);
//         }
//         it++;
//     }
//     m_hetroBackupJobObj->m_dataFs.path.clear();
//     EXPECT_EQ(m_hetroBackupJobObj->InitJobInfo(), false);


//     backupJob = BackupJobSetup();
//     jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
//     m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
//     m_hetroBackupJobObj->GetBackupJobInfo();
//     m_hetroBackupJobObj->m_backupJobPtr->jobParam.backupType = AppProtect::BackupJobType::INCREMENT_BACKUP;
//     EXPECT_EQ(m_hetroBackupJobObj->InitJobInfo(), true);

//     backupJob = BackupJobSetup();
//     jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
//     m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
//     m_hetroBackupJobObj->GetBackupJobInfo();
//     m_hetroBackupJobObj->m_backupJobPtr->jobParam.backupType = AppProtect::BackupJobType::INCREMENT_BACKUP;
//     m_hetroBackupJobObj->m_jobCtrlPhase = JOB_CTRL_PHASE_ALLOWLOCALNODE;
//     stub.set(ADDR(HetroCommonService, ReadBackupCopyFromFile), ReadBackupCopyFromFile_Stub_SUC);
//     EXPECT_EQ(m_hetroBackupJobObj->InitJobInfo(), true);
//     stub.reset(ADDR(HetroCommonService, ReadBackupCopyFromFile));

//     backupJob = BackupJobSetup();
//     jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
//     m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
//     m_hetroBackupJobObj->GetBackupJobInfo();
//     m_hetroBackupJobObj->m_jobCtrlPhase = JOB_CTRL_PHASE_CHECKBACKUPJOBTYPE;
//     m_hetroBackupJobObj->m_nasShare.nasShareExt.m_protocol = NAS_PROTOCOL_TYPE_E_CIFS;
//     EXPECT_EQ(m_hetroBackupJobObj->InitJobInfo(), true);

//     backupJob = BackupJobSetup();
//     jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
//     m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
//     m_hetroBackupJobObj->GetBackupJobInfo();
//     m_hetroBackupJobObj->m_jobCtrlPhase = JOB_CTRL_PHASE_CHECKBACKUPJOBTYPE;
//     m_hetroBackupJobObj->m_backupJobPtr->protectObject.extendInfo = "{\"shareMode\":\"0\"}";
//     m_hetroBackupJobObj->m_backupJobPtr->protectObject.auth.authType = AuthType::type::KERBEROS;
//     EXPECT_EQ(m_hetroBackupJobObj->InitJobInfo(), false);

//     backupJob = BackupJobSetup();
//     jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
//     m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
//     m_hetroBackupJobObj->GetBackupJobInfo();
//     m_hetroBackupJobObj->m_jobCtrlPhase = JOB_CTRL_PHASE_CHECKBACKUPJOBTYPE;
//     m_hetroBackupJobObj->m_backupJobPtr->protectObject.extendInfo = "{\"shareMode\":\"0\"}";
//     m_hetroBackupJobObj->m_backupJobPtr->protectObject.auth.authType = AuthType::type::KERBEROS;
//     m_hetroBackupJobObj->m_backupJobPtr->protectObject.auth.extendInfo = "{}";
//     EXPECT_EQ(m_hetroBackupJobObj->InitJobInfo(), false);

//     backupJob = BackupJobSetup();
//     jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
//     m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
//     m_hetroBackupJobObj->GetBackupJobInfo();
//     m_hetroBackupJobObj->m_jobCtrlPhase = JOB_CTRL_PHASE_CHECKBACKUPJOBTYPE;
//     m_hetroBackupJobObj->m_backupJobPtr->protectObject.extendInfo = "{\"shareMode\":\"0\"}";
//     m_hetroBackupJobObj->m_backupJobPtr->protectObject.auth.authType = AuthType::type::KERBEROS;
//     m_hetroBackupJobObj->m_backupJobPtr->protectObject.auth.extendInfo = "{}";
//     stub.set(PluginUtils::KinitTGTInner, KinitTGTInner_Stub_Fail);
//     EXPECT_EQ(m_hetroBackupJobObj->InitJobInfo(), true);
//     stub.reset(PluginUtils::KinitTGTInner);
// }

/*
 * 用例名称: GetBackupJobInfo
 * 前置条件：无
 * check点：初始化GetBackupJobInfo函数分支场景
 */
TEST_F(HetroBackupJobTest, GetBackupJobInfo)
{
    m_hetroBackupJobObj->m_jobCommonInfo = nullptr;
    m_hetroBackupJobObj->m_backupJobPtr = nullptr;
    EXPECT_EQ(m_hetroBackupJobObj->GetBackupJobInfo(), false);
}

/*
 * 用例名称: PrerequisiteJobInner
 * 前置条件：无
 * check点：初始化PrerequisiteJobInner函数分支场景
 */
TEST_F(HetroBackupJobTest, PrerequisiteJobInner)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    m_hetroBackupJobObj->GetBackupJobInfo();
    m_hetroBackupJobObj->m_backupJobPtr->protectEnv.extendInfo = "test";
    EXPECT_EQ(m_hetroBackupJobObj->PrerequisiteJobInner(), Module::FAILED);
}

/*
 * 用例名称: CheckSmbConnectVersion
 * 前置条件：无
 * check点：初始化CheckSmbConnectVersion函数分支场景
 */
TEST_F(HetroBackupJobTest, CheckSmbConnectVersion)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    m_hetroBackupJobObj->GetBackupJobInfo();
    m_hetroBackupJobObj->m_backupJobPtr->protectEnv.extendInfo = "test";
    int64_t errCode;
    HetroLastCopyDetails copyDetail;
    Module::SmbVersion smbVersion = HetroCommonService::ConvertStringToSmbVersion(copyDetail.m_protocolVersion);
    EXPECT_EQ(m_hetroBackupJobObj->CheckSmbConnectVersion(smbVersion, errCode), false);


    backupJob = BackupJobSetup();
    jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    m_hetroBackupJobObj->GetBackupJobInfo();
    m_hetroBackupJobObj->m_backupJobPtr->protectEnv.extendInfo = "test";
    m_hetroBackupJobObj->m_backupJobPtr->protectObject.auth.authType = AuthType::type::KERBEROS;
    EXPECT_EQ(m_hetroBackupJobObj->CheckSmbConnectVersion(smbVersion, errCode), false);

    backupJob = BackupJobSetup();
    jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    m_hetroBackupJobObj->GetBackupJobInfo();
    m_hetroBackupJobObj->m_backupJobPtr->protectEnv.extendInfo = "test";
    m_hetroBackupJobObj->m_backupJobPtr->protectObject.auth.authType = AuthType::type::NO_AUTHENTICATION;
    EXPECT_EQ(m_hetroBackupJobObj->CheckSmbConnectVersion(smbVersion, errCode), false);

    backupJob = BackupJobSetup();
    jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    m_hetroBackupJobObj->GetBackupJobInfo();
    m_hetroBackupJobObj->m_backupJobPtr->protectEnv.extendInfo = "test";
    m_hetroBackupJobObj->m_backupJobPtr->protectObject.auth.authType = AuthType::type::OS_PASSWORD;
    EXPECT_EQ(m_hetroBackupJobObj->CheckSmbConnectVersion(smbVersion, errCode), false);

    backupJob = BackupJobSetup();
    jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    m_hetroBackupJobObj->GetBackupJobInfo();
    m_hetroBackupJobObj->m_backupJobPtr->protectEnv.extendInfo = "test";
    m_hetroBackupJobObj->m_backupJobPtr->protectObject.auth.authType = AuthType::type::APP_PASSWORD;
    EXPECT_EQ(m_hetroBackupJobObj->CheckSmbConnectVersion(smbVersion, errCode), false);

    backupJob = BackupJobSetup();
    jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    m_hetroBackupJobObj->GetBackupJobInfo();
    m_hetroBackupJobObj->m_backupJobPtr->protectEnv.extendInfo = "test";
    m_hetroBackupJobObj->m_backupJobPtr->protectObject.auth.authType = AuthType::type::OTHER;
    EXPECT_EQ(m_hetroBackupJobObj->CheckSmbConnectVersion(smbVersion, errCode), false);
}


static bool CreateSnapshot_Stub_Suc()
{
    return true;
}

static bool CreateSnapshot_Stub_fail()
{
    return false;
}

static bool CheckDeviceNetworkConnect_Stub_Suc()
{
    return true;
}

/*
 * 用例名称: SetupRemoteNasForBackupJob
 * 前置条件：无
 * check点：初始化SetupRemoteNasForBackupJob函数分支场景
 */
TEST_F(HetroBackupJobTest, SetupRemoteNasForBackupJob)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    m_hetroBackupJobObj->m_nasHost.nasHostExt.m_useSnapshot = "1";
    m_hetroBackupJobObj->m_generalInfo.m_remoteNasShareSnapshotName = "name";
    stub.set(ADDR(PluginUtils,CheckDeviceNetworkConnect), CheckDeviceNetworkConnect_Stub_Suc);
    EXPECT_EQ(m_hetroBackupJobObj->SetupRemoteNasForBackupJob(), true);
    stub.reset(ADDR(PluginUtils, CheckDeviceNetworkConnect));

    backupJob = BackupJobSetup();
    jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    m_hetroBackupJobObj->m_nasHost.nasHostExt.m_useSnapshot = "1";
    m_hetroBackupJobObj->m_generalInfo.m_remoteNasShareSnapshotName = "";
    stub.set(ADDR(HetroCommonService, CreateSnapshot), CreateSnapshot_Stub_Suc);
    stub.set(ADDR(PluginUtils,CheckDeviceNetworkConnect), CheckDeviceNetworkConnect_Stub_Suc);
    EXPECT_EQ(m_hetroBackupJobObj->SetupRemoteNasForBackupJob(), true);
    stub.reset(ADDR(HetroCommonService, CreateSnapshot));
    stub.reset(ADDR(PluginUtils, CheckDeviceNetworkConnect));


    backupJob = BackupJobSetup();
    jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    m_hetroBackupJobObj->m_nasHost.nasHostExt.m_useSnapshot = "1";
    m_hetroBackupJobObj->m_generalInfo.m_remoteNasShareSnapshotName = "";
    stub.set(ADDR(HetroCommonService, CreateSnapshot), CreateSnapshot_Stub_fail);
    stub.set(ADDR(PluginUtils,CheckDeviceNetworkConnect), CheckDeviceNetworkConnect_Stub_Suc);
    EXPECT_EQ(m_hetroBackupJobObj->SetupRemoteNasForBackupJob(), false);
    stub.reset(ADDR(HetroCommonService, CreateSnapshot));
    stub.reset(ADDR(PluginUtils, CheckDeviceNetworkConnect));

    backupJob = BackupJobSetup();
    jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    m_hetroBackupJobObj->m_nasHost.nasHostExt.m_useSnapshot = "1";
    m_hetroBackupJobObj->m_generalInfo.m_remoteNasShareSnapshotName = "";
    stub.set(ADDR(HetroCommonService, CreateSnapshot), CreateSnapshot_Stub_fail);
    stub.set(ADDR(PluginUtils,CheckDeviceNetworkConnect), CheckDeviceNetworkConnect_Stub_Suc);
    EXPECT_EQ(m_hetroBackupJobObj->SetupRemoteNasForBackupJob(), false);
    stub.reset(ADDR(HetroCommonService, CreateSnapshot));
    stub.reset(ADDR(PluginUtils, CheckDeviceNetworkConnect));

    backupJob = BackupJobSetup();
    jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    m_hetroBackupJobObj->m_nasHost.nasHostExt.m_useSnapshot = "1";
    m_hetroBackupJobObj->m_generalInfo.m_remoteNasShareSnapshotName = "";
    stub.set(ADDR(HetroCommonService, CreateSnapshot), CreateSnapshot_Stub_fail);
    stub.set(ADDR(PluginUtils, CheckDeviceNetworkConnect), CheckDeviceNetworkConnect_Stub_Suc);
    EXPECT_EQ(m_hetroBackupJobObj->SetupRemoteNasForBackupJob(), false);
    stub.reset(ADDR(PluginUtils, CheckDeviceNetworkConnect));
    stub.reset(ADDR(HetroCommonService, CreateSnapshot));
}

static bool GetSharedResources_Stub_Suc()
{
    return true;
}

static bool GetSharedResources_Stub_Fail()
{
    return false;
}

static bool WriteBackupCopyToFile_Stub_Suc()
{
    return true;
}

static bool WriteBackupCopyToFile_Stub_Fail()
{
    return false;
}

/*
 * 用例名称: ExecuteTeardownSubJobInner
 * 前置条件：无
 * check点：初始化ExecuteTeardownSubJobInner函数分支场景
 */
TEST_F(HetroBackupJobTest, ExecuteTeardownSubJobInner)
{
    HetroBackupJob ins;
    AppProtect::BackupJob backupJob = BackupJobSetup();
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    ins.m_jobCommonInfo = jobInfo;

    HetroBackupSubJob backupSubJob;
    backupSubJob.m_SubTaskType = SUBJOB_TYPE_TEARDOWN_PHASE;
    string backupSubJobStr;
    Module::JsonHelper::StructToJsonString(backupSubJob, backupSubJobStr);
    SubJob subJob;
    subJob.jobInfo = backupSubJobStr;
    ins.SetSubJob(std::make_shared<SubJob>(subJob));

    stub.set(ADDR(HetroCommonService, WriteBackupCopyToFile), WriteBackupCopyToFile_Stub_Suc);
    EXPECT_EQ(ins.ExecuteSubJob(), Module::SUCCESS);
    stub.reset(ADDR(HetroCommonService, WriteBackupCopyToFile));

    backupJob = BackupJobSetup();
    jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    ins.m_jobCommonInfo = jobInfo;
    ins.GetBackupJobInfo();
    stub.set(ADDR(HetroBackupJob, InitJobInfo), InitJobInfo_STUB_SUCC);
    stub.set(ADDR(HetroCommonService, GetSharedResources), GetSharedResources_Stub_Fail);
    EXPECT_EQ(ins.ExecuteSubJob(), Module::FAILED);
    stub.reset(ADDR(HetroBackupJob, InitJobInfo));
    stub.reset(ADDR(HetroCommonService, GetSharedResources));

    backupJob = BackupJobSetup();
    jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    ins.m_jobCommonInfo = jobInfo;
    ins.GetBackupJobInfo();
    stub.set(ADDR(HetroBackupJob, InitJobInfo), InitJobInfo_STUB_SUCC);
    stub.set(ADDR(HetroCommonService, GetSharedResources), GetSharedResources_Stub_Suc);
    stub.set(ADDR(HetroCommonService, WriteBackupCopyToFile), WriteBackupCopyToFile_Stub_Fail);
    EXPECT_EQ(ins.ExecuteSubJob(), Module::FAILED);
    stub.reset(ADDR(HetroBackupJob, InitJobInfo));
    stub.reset(ADDR(HetroCommonService, GetSharedResources));
    stub.reset(ADDR(HetroCommonService, WriteBackupCopyToFile));

    backupJob = BackupJobSetup();
    jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    ins.m_jobCommonInfo = jobInfo;
    ins.GetBackupJobInfo();
    stub.set(ADDR(HetroBackupJob, InitJobInfo), InitJobInfo_STUB_SUCC);
    stub.set(ADDR(HetroCommonService, GetSharedResources), GetSharedResources_Stub_Suc);
    stub.set(ADDR(HetroCommonService, WriteBackupCopyToFile), WriteBackupCopyToFile_Stub_Suc);
    EXPECT_EQ(ins.ExecuteSubJob(), Module::SUCCESS);
    stub.reset(ADDR(HetroBackupJob, InitJobInfo));
    stub.reset(ADDR(HetroCommonService, GetSharedResources));
    stub.reset(ADDR(HetroCommonService, WriteBackupCopyToFile));
    stub.reset(ADDR(HetroBackupJob, IsAggregate));
}

/*
 * 用例名称: ExecuteCopyMetaSubJobInner
 * 前置条件：无
 * check点：初始化ExecuteCopyMetaSubJobInner函数分支场景
 */
TEST_F(HetroBackupJobTest, ExecuteCopyMetaSubJobInner)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    m_hetroBackupJobObj->GetBackupJobInfo();
    stub.set(ADDR(HetroBackupJob, ExecuteCopyMetaSubJobInner), ExecuteCopyMetaSubJobInner_Stub);
    HetroBackupSubJob backupSubJob;
    EXPECT_EQ(m_hetroBackupJobObj->ExecuteCopyMetaSubJobInner(backupSubJob), Module::SUCCESS);
    stub.reset(ADDR(HetroBackupJob, ExecuteCopyMetaSubJobInner));
}

static bool InitSubTask_Stub_Suc()
{
    return true;
}

static bool InitSubTask_Stub_Fail()
{
    return false;
}

/*
 * 用例名称: GenerateSubJobList
 * 前置条件：无
 * check点：初始化GenerateSubJobList函数分支场景
 */
TEST_F(HetroBackupJobTest, GenerateSubJobList)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    m_hetroBackupJobObj->GetBackupJobInfo();
    std::vector<SubJob> subJobList;
    std::vector<std::string> ctrlFileList;
    std::string dstCtrlFileRelPath;
    std::string ctrlFileFullPath;
    stub.set(ADDR(HetroCommonService, InitSubTask), InitSubTask_Stub_Fail);
    EXPECT_EQ(m_hetroBackupJobObj->GenerateSubJobList(subJobList, ctrlFileList, dstCtrlFileRelPath, ctrlFileFullPath),
        false);
    stub.reset(ADDR(HetroCommonService, InitSubTask));


    backupJob = BackupJobSetup();
    jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    stub.set(ADDR(HetroCommonService, InitSubTask), InitSubTask_Stub_Suc);
    EXPECT_EQ(m_hetroBackupJobObj->GenerateSubJobList(subJobList, ctrlFileList, dstCtrlFileRelPath, ctrlFileFullPath),
        true);
    stub.reset(ADDR(HetroCommonService, InitSubTask));
}

static bool PathExistMandate_Stuc_Suc()
{
    return true;
}

static bool GetFileListInDirectory_Stuc_Suc(const std::string &path, std::vector<std::string> &fileList)
{
    fileList.push_back("file1/test/test/test/test/a.txt");
    return true;
}

static bool IsValidCtrlFile_Stub_Fail()
{
    return false;
}

static bool IsValidCtrlFile_Stub_Suc()
{
    return true;
}

static bool GenerateSubJobList_Stub_fail()
{
    return false;
}

static bool GenerateSubJobList_Stub_Suc()
{
    return true;
}

static int CreateSubTask_Stub_Fail()
{
    return Module::FAILED;
}

/*
 * 用例名称: CreateSubTasksFromCtrlFile
 * 前置条件：无
 * check点：初始化CreateSubTasksFromCtrlFile函数分支场景
 */
TEST_F(HetroBackupJobTest, CreateSubTasksFromCtrlFile)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    m_hetroBackupJobObj->GetBackupJobInfo();
    m_hetroBackupJobObj->m_cacheFsPath = "test";
    std::string srcDir;
    std::string dstDir;
    uint32_t subTaskType;
    bool isFinal = false;
    EXPECT_EQ(m_hetroBackupJobObj->CreateSubTasksFromCtrlFile(srcDir, dstDir, subTaskType, isFinal), true);


    backupJob = BackupJobSetup();
    jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    stub.set(PluginUtils::PathExistMandate, PathExistMandate_Stuc_Suc);
    stub.set(PluginUtils::GetFileListInDirectory, GetFileListInDirectory_Stuc_Suc);
    EXPECT_EQ(m_hetroBackupJobObj->CreateSubTasksFromCtrlFile(srcDir, dstDir, subTaskType, isFinal), true);
    stub.reset(PluginUtils::PathExistMandate);
    stub.reset(PluginUtils::GetFileListInDirectory);

    backupJob = BackupJobSetup();
    jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    stub.set(PluginUtils::PathExistMandate, PathExistMandate_Stuc_Suc);
    stub.set(PluginUtils::GetFileListInDirectory, GetFileListInDirectory_Stuc_Suc);
    stub.set(ADDR(BasicJob, IsAbortJob), IsAbortJob_Stub_True);
    EXPECT_EQ(m_hetroBackupJobObj->CreateSubTasksFromCtrlFile(srcDir, dstDir, subTaskType, isFinal), true);
    stub.reset(PluginUtils::PathExistMandate);
    stub.reset(PluginUtils::GetFileListInDirectory);
    stub.reset(ADDR(BasicJob, IsAbortJob));

    backupJob = BackupJobSetup();
    jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    stub.set(PluginUtils::PathExistMandate, PathExistMandate_Stuc_Suc);
    stub.set(PluginUtils::GetFileListInDirectory, GetFileListInDirectory_Stuc_Suc);
    stub.set(ADDR(HetroCommonService, IsValidCtrlFile), IsValidCtrlFile_Stub_Fail);
    EXPECT_EQ(m_hetroBackupJobObj->CreateSubTasksFromCtrlFile(srcDir, dstDir, subTaskType, isFinal), true);
    stub.reset(PluginUtils::PathExistMandate);
    stub.reset(PluginUtils::GetFileListInDirectory);
    stub.reset(ADDR(HetroCommonService, IsValidCtrlFile));

    backupJob = BackupJobSetup();
    jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    stub.set(PluginUtils::PathExistMandate, PathExistMandate_Stuc_Suc);
    stub.set(PluginUtils::GetFileListInDirectory, GetFileListInDirectory_Stuc_Suc);
    stub.set(ADDR(HetroCommonService, IsValidCtrlFile), IsValidCtrlFile_Stub_Fail);
    EXPECT_EQ(m_hetroBackupJobObj->CreateSubTasksFromCtrlFile(srcDir, dstDir, subTaskType, isFinal), true);
    stub.reset(PluginUtils::PathExistMandate);
    stub.reset(PluginUtils::GetFileListInDirectory);
    stub.reset(ADDR(HetroCommonService, IsValidCtrlFile));

    backupJob = BackupJobSetup();
    jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    stub.set(PluginUtils::PathExistMandate, PathExistMandate_Stuc_Suc);
    stub.set(PluginUtils::GetFileListInDirectory, GetFileListInDirectory_Stuc_Suc);
    stub.set(ADDR(HetroCommonService, IsValidCtrlFile), IsValidCtrlFile_Stub_Suc);
    stub.set(ADDR(HetroBackupJob, GenerateSubJobList), GenerateSubJobList_Stub_fail);
    EXPECT_EQ(m_hetroBackupJobObj->CreateSubTasksFromCtrlFile(srcDir, dstDir, subTaskType, isFinal), true);
    stub.reset(PluginUtils::PathExistMandate);
    stub.reset(PluginUtils::GetFileListInDirectory);
    stub.reset(ADDR(HetroCommonService, IsValidCtrlFile));
    stub.reset(ADDR(HetroBackupJob, GenerateSubJobList));

    backupJob = BackupJobSetup();
    jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    stub.set(PluginUtils::PathExistMandate, PathExistMandate_Stuc_Suc);
    stub.set(PluginUtils::GetFileListInDirectory, GetFileListInDirectory_Stuc_Suc);
    stub.set(ADDR(HetroCommonService, IsValidCtrlFile), IsValidCtrlFile_Stub_Suc);
    stub.set(ADDR(HetroBackupJob, GenerateSubJobList), GenerateSubJobList_Stub_Suc);
    stub.set((int (HetroCommonService::*)(std::vector<SubJob> &, std::vector<std::string> &))ADDR(HetroCommonService,
        CreateSubTask),
        CreateSubTask_Stub_Fail);
    EXPECT_EQ(m_hetroBackupJobObj->CreateSubTasksFromCtrlFile(srcDir, dstDir, subTaskType, isFinal), true);
    stub.reset(PluginUtils::PathExistMandate);
    stub.reset(PluginUtils::GetFileListInDirectory);
    stub.reset(ADDR(HetroCommonService, IsValidCtrlFile));
    stub.reset(ADDR(HetroBackupJob, GenerateSubJobList));
    stub.reset((int (HetroCommonService::*)(std::vector<SubJob> &, std::vector<std::string> &))ADDR(HetroCommonService,
        CreateSubTask));
}

static int GetCurrentTimeFromRemoteServer_Stub_1(int &time)
{
    return 1;
}

static int GetCurrentTimeFromRemoteServer_Stub_0(int &time)
{
    return 0;
}

static bool UpdateGeneralResource_Stub_Suc()
{
    return true;
}

/*
 * 用例名称: UpdateCopyPhaseStartTimeInGenRsc
 * 前置条件：无
 * check点：初始化UpdateCopyPhaseStartTimeInGenRsc函数分支场景
 */
TEST_F(HetroBackupJobTest, UpdateCopyPhaseStartTimeInGenRsc)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    m_hetroBackupJobObj->GetBackupJobInfo();
    m_hetroBackupJobObj->m_generalInfo.m_backupCopyPhaseStartTime = 1;
    EXPECT_EQ(m_hetroBackupJobObj->UpdateCopyPhaseStartTimeInGenRsc(), true);


    backupJob = BackupJobSetup();
    jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    m_hetroBackupJobObj->m_generalInfo.m_backupCopyPhaseStartTime = 0;
    stub.set(ADDR(HetroCommonService, GetCurrentTimeFromRemoteServer), GetCurrentTimeFromRemoteServer_Stub_0);
    EXPECT_EQ(m_hetroBackupJobObj->UpdateCopyPhaseStartTimeInGenRsc(), false);
    stub.reset(ADDR(HetroCommonService, GetCurrentTimeFromRemoteServer));

    backupJob = BackupJobSetup();
    jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    m_hetroBackupJobObj->m_generalInfo.m_backupCopyPhaseStartTime = 0;
    stub.set(ADDR(HetroCommonService, GetCurrentTimeFromRemoteServer), GetCurrentTimeFromRemoteServer_Stub_1);
    EXPECT_EQ(m_hetroBackupJobObj->UpdateCopyPhaseStartTimeInGenRsc(), true);
    stub.reset(ADDR(HetroCommonService, GetCurrentTimeFromRemoteServer));

    backupJob = BackupJobSetup();
    jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    m_hetroBackupJobObj->m_generalInfo.m_backupCopyPhaseStartTime = 0;
    stub.set(ADDR(HetroCommonService, GetCurrentTimeFromRemoteServer), GetCurrentTimeFromRemoteServer_Stub_1);
    stub.set(ADDR(HetroCommonService, UpdateGeneralResource), UpdateGeneralResource_Stub_FAIL);
    EXPECT_EQ(m_hetroBackupJobObj->UpdateCopyPhaseStartTimeInGenRsc(), false);
    stub.reset(ADDR(HetroCommonService, GetCurrentTimeFromRemoteServer));
    stub.reset(ADDR(HetroCommonService, UpdateGeneralResource));

    backupJob = BackupJobSetup();
    jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    m_hetroBackupJobObj->m_generalInfo.m_backupCopyPhaseStartTime = 0;
    stub.set(ADDR(HetroCommonService, GetCurrentTimeFromRemoteServer), GetCurrentTimeFromRemoteServer_Stub_1);
    stub.set(ADDR(HetroCommonService, UpdateGeneralResource), UpdateGeneralResource_Stub_Suc);
    EXPECT_EQ(m_hetroBackupJobObj->UpdateCopyPhaseStartTimeInGenRsc(), true);
    stub.reset(ADDR(HetroCommonService, GetCurrentTimeFromRemoteServer));
    stub.reset(ADDR(HetroCommonService, UpdateGeneralResource));
}

static bool CheckRemoteNasMount_Stub_Fail()
{
    return false;
}

static bool CheckRemoteNasMount_Stub_Suc()
{
    return true;
}

static bool CheckDataFsMount_Stub_Fail()
{
    return false;
}

/*
 * 用例名称: CheckMountVersion
 * 前置条件：无
 * check点：初始化CheckMountVersion函数分支场景
 */
TEST_F(HetroBackupJobTest, CheckMountVersion)
{
    AppProtect::BackupJob backupJob = BackupJobSetup();
    std::shared_ptr<JobCommonInfo> jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    m_hetroBackupJobObj->GetBackupJobInfo();
    std::string proto;
    std::string protoVersion;
    int64_t errCode;
    stub.set(ADDR(PluginUtils, MountNFS), MountNas_Stub_SUC);
    stub.set(ADDR(PluginUtils, UnmountNas), UnmountNas_Stub_SUC);
    EXPECT_EQ(m_hetroBackupJobObj->CheckMountVersion(proto, protoVersion, errCode), false);
    stub.reset(ADDR(PluginUtils, MountNFS));
    stub.reset(ADDR(PluginUtils, UnmountNas));


    backupJob = BackupJobSetup();
    jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    m_hetroBackupJobObj->GetBackupJobInfo();
    stub.set(ADDR(HetroCommonService, CheckRemoteNasMount), CheckRemoteNasMount_Stub_Suc);
    stub.set(ADDR(PluginUtils, MountNFS), MountNas_Stub_SUC);
    stub.set(ADDR(PluginUtils, UnmountNas), UnmountNas_Stub_SUC);
    EXPECT_EQ(m_hetroBackupJobObj->CheckMountVersion(proto, protoVersion, errCode), false);
    stub.reset(ADDR(HetroCommonService, CheckRemoteNasMount));
    stub.reset(ADDR(PluginUtils, MountNFS));
    stub.reset(ADDR(PluginUtils, UnmountNas));

    backupJob = BackupJobSetup();
    jobInfo = make_shared<JobCommonInfo>(make_shared<BackupJob>(backupJob));
    m_hetroBackupJobObj->m_jobCommonInfo = jobInfo;
    m_hetroBackupJobObj->GetBackupJobInfo();
    stub.set(ADDR(HetroCommonService, CheckDataFsMount), CheckDataFsMount_Stub_Fail);
    stub.set(ADDR(PluginUtils, MountNFS), MountNas_Stub_SUC);
    stub.set(ADDR(PluginUtils, UnmountNas), UnmountNas_Stub_SUC);
    EXPECT_EQ(m_hetroBackupJobObj->CheckMountVersion(proto, protoVersion, errCode), false);
    stub.reset(ADDR(HetroCommonService, CheckDataFsMount));
    stub.reset(ADDR(PluginUtils, MountNFS));
    stub.reset(ADDR(PluginUtils, UnmountNas));
}

TEST_F(HetroBackupJobTest, CopyMetaFileToMetaRepo)
{
    m_hetroBackupJobObj->m_cacheFsPath = "test";
    std::string scanMetaFilePath = m_hetroBackupJobObj->m_cacheFsPath + "/backup-job/scan/meta/latest";

    stub.set(PluginUtils::PathExistMandate, PathExistMandate_Stuc_Suc);
    stub.set(PluginUtils::RemoveFile, GetFileListInDirectory_Stuc_Suc);
    //EXPECT_EQ(m_hetroBackupJobObj->CopyMetaFileToMetaRepo(scanMetaFilePath), Module::SUCCESS);
    stub.reset(PluginUtils::PathExistMandate);
    stub.reset(PluginUtils::RemoveFile);
}

TEST_F(HetroBackupJobTest, IsSnapshotEnabled)
{
    m_hetroBackupJobObj->IsSnapshotEnabled();
}

TEST_F(HetroBackupJobTest, ReportScannerRunningStatus)
{
    HetroNativeScanStatistics scanStatistics {};
    m_hetroBackupJobObj->ReportScannerRunningStatus(scanStatistics);
}